﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChoDiaOc_HK_WPF.Models;

namespace ChoDiaOc_HK_WPF.Views.LapBaoBieu
{
    class TKDiaOc
    {
        private string m_MaDiaOc;

        public string MaDiaOc
        {
            get { return m_MaDiaOc; }
            set { m_MaDiaOc = value; }
        }
        private string m_TenLoaiDiaOc;

        public string TenLoaiDiaOc
        {
            get { return m_TenLoaiDiaOc; }
            set { m_TenLoaiDiaOc = value; }
        }
        private string m_TenKhachHang;

        public string TenKhachHang
        {
            get { return m_TenKhachHang; }
            set { m_TenKhachHang = value; }
        }
        private string m_GiaBan;

        public string GiaBan
        {
            get { return m_GiaBan; }
            set { m_GiaBan = value; }
        }
        private string m_TrangThai;

        public string TrangThai
        {
            get { return m_TrangThai; }
            set { m_TrangThai = value; }
        }

        
        public static List<TKDiaOc> getListDiaOc(List<DIAOC> listOld, int thang, int nam)
        {
            List<TKDiaOc> listNew = new List<TKDiaOc>();
            try
            {
                foreach (DIAOC d in listOld)
                {
                    DBEntities entities = new DBEntities();
                    TKDiaOc temp = new TKDiaOc();
                    temp.MaDiaOc = d.MaDiaOc;
                    temp.TenLoaiDiaOc = entities.LOAIDIAOCs.Where(t => t.MaLoaiDiaOc == d.MaLoaiDiaOc).SingleOrDefault().TenLoaiDiaOc;
                    string m_MaKH = entities.PHIEUDANGKies.Where(t1 => t1.MaDiaOc == d.MaDiaOc).SingleOrDefault().MaKH;
                    temp.TenKhachHang = entities.KHACHHANGs.Where(t2 => t2.MaKH == m_MaKH).SingleOrDefault().HoTen;
                    temp.GiaBan = d.GiaBan;
                    temp.TrangThai = d.TrangThai;
                    DateTime thangnam = entities.PHIEUDANGKies.Where(t1 => t1.MaDiaOc == d.MaDiaOc).SingleOrDefault().TuNgay;
                    if (thang == thangnam.Month && nam == thangnam.Year)
                        listNew.Add(temp);
                }
            }catch(Exception ex) {
            }
            return listNew;
        }
    }
}
